﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iBuproModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using iBuproModel.Repositories.Classes;
using System.Collections;
using IBupro.Models.Classes;
using iBuproModel.Repositories;
using iBuproModel.Repositories.Interfaces;


namespace IBupro.Models
{
    public class StudentFieldModel : CustomModel
    {

        public StudentFieldModel()
        {
        }

        public StudentFieldModel(string Name, string Shortcut, int StudentPlanId)
        {
            this.Name = Name;
            this.Shortcut = Shortcut;
            this.StudentPlan = StudentPlanId;
        }

        [Required(ErrorMessage="You must speciify name")]
        public string Name { get; set; }

        [Required(ErrorMessage = "You must speciify shortcut")]
        public string Shortcut { get; set; }

        public int StudentPlan { get; set; }

        public MultiSelectList MultiSelectListSubjects(string[] selectedItems)
        {
            ISubjectRepository repository = repositoryService.SubjectRepositoryCreateInstace();

            IEnumerable subjects = from s in repository.GetAll().ToList()
                                   select new
                                   {
                                       Id = s.Id,
                                       Name = String.Format("({0}) {1}", s.Shortcut, s.Name)
                                   };

            return new MultiSelectList(subjects, "Id", "Name", selectedItems);
        }

        public MultiSelectList MultiSelectListSubjects()
        {
            return MultiSelectListSubjects(null);
        }

        public SelectList GetStudentPlanList()
        {
            StudentPlanRepository studentPlans = new StudentPlanRepository();
            //List<StudentPlan> plans = studentPlans.GetAll().ToList();

            List<SelectListItem> list = (from p in studentPlans.GetAll().ToList()
                    select new SelectListItem
                    {
                        Value = p.Id.ToString(),
                        Text = String.Format("({0}) {1}", p.Shortcut, p.Name),
                        Selected = false
                    }).ToList();

            return new SelectList(list, "Value", "Text");
        }
        
        public IEnumerable<int> SelectedSubjects { get; set; }



    }
}